package com.kgc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kgc.entity.Result;
import com.kgc.pojo.OrderCart;
import com.kgc.pojo.OrderMaster;
import com.kgc.service.BackOrderCartService;
import com.kgc.service.BackOrderMasterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : nanqiong
 * @date：Created in 2020/11/18
 * @description:
 * @nersion: 1.0
 */
@Slf4j
@RestController
@RequestMapping("backOrderMaster")
public class BackOrderMasterController {

    @Autowired
    private BackOrderMasterService backOrderMasterService;
    @Autowired
    private BackOrderCartService backOrderCartService;
    /**
     * 条件查询订单列表
     * @return返回列表
     * @prams：当前页码currentPage,每页显示条数 pageSize,搜索内容 orderTableNum,创建时间 createTime
     */
    @PostMapping("backFindOrder")
    public Result backFindOrder(Integer currentPage,Integer pageSize,String orderTableNum,String createTime){
        log.info("按订单编号，创建时间，桌号，条件查询");
        Page<OrderMaster> page = new Page<>(currentPage,pageSize);
        QueryWrapper<OrderMaster> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("order_table_num",orderTableNum).like("create_time",createTime);
        IPage<OrderMaster> pages = backOrderMasterService.page(page, queryWrapper);
        log.info("查询成功"+pages);
        return new Result(true,"查询订单成功",pages);
    }

    /**
     * 查询订单详情
     * @prams 参数为订单编号，openid，桌号，
     */
    @PostMapping("backOrderDetail")
    public Result backOrderDetail(Integer currentPage,Integer pageSize,String orderNumber,String openId,String orderTableNum){
        log.info("按订单编号，用户openid，桌号，条件查询");
        Page<OrderCart> page = new Page<>(currentPage,pageSize);
        QueryWrapper<OrderCart> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("order_table_num",orderTableNum).like("order_number",orderNumber).like("buyer_openid",openId);
        Page<OrderCart> page1 = backOrderCartService.page(page,queryWrapper);
        log.info("查询详情成功"+page1);
        return new Result(true,"查询订单详情成功",page1);
    }
}
